<!--219970838杨彪-->
<!DOCTYPE html><html><head>  
  <meta charset="UTF-8">   
   <title>AJAX 判断用户名是否存在</title>  
	 <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>  
	   <script src="js/check-username.js"></script></head><body> 
		  <form>       
		   <label for="username">用户名：</label>      
			<input type="text" id="username" name="username">     
			   <button type="button" id="check-btn">检查</button>    
				   <p id="result"></p>    </form></body></html>
        <script>
			 $('#check-btn').click(function() {  
			 var username = $('#username').val();     
			   
			$.ajax({                
				      type: 'GET',           
				      url: 'http://127.0.0.1:4523/m1/2834515-0-default/user?name=yy',                
				  dataType: 'json',  
					success: function(data) { 
					if (data.name == $('#username').val()) {   
					$('#result').text('用户名已存在');             
						   } 
			 else {                      
						$('#result').text('用户名可用'); 
						 }},		
			   
								    });})
								 
</script>
		</div>
	</body>
</html>